package site.model;

import org.springframework.stereotype.Repository;
import site.entity.User;

import java.util.List;

@Repository
public class UserDao extends JpaGenericDao<User> {
    public User getUserByUsername(String username) {
        javax.persistence.Query query = em.createQuery("select user from User user " +
                "where user.username=:username")
                .setParameter("username", username);
        User user = (User) query.getSingleResult();
        user.getRoles().size();
        return user;
    }


    public List getAllAdmins() {
        javax.persistence.Query query = em.createQuery("select user from User user inner join" +
                " user.roles role where role.authority=:ROLE")
                .setParameter("ROLE", "ROLE_ADMIN");
        return query.getResultList();
    }
}
